package com.atguigu.controller;

import com.atguigu.pojo.Dept;
import com.atguigu.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-02-07
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @PostMapping("/dept")
    public String InsertDept(@RequestBody Dept dept) {
        deptService.insertDept(dept);
        log.info("insertdept:"+dept);
        return "{info:ok}";
    }

    @PutMapping("/dept")
    public String UpdateDept(@RequestBody Dept dept) {
        deptService.updateDept(dept);
        log.info("updatedept:"+dept);
        return "{info:ok}";
    }

    @DeleteMapping("/dept/{did}")
    public String DeleteDept(@PathVariable("did") Integer did) {
        deptService.deleteDept(did);
        log.info("deletedept:"+did);
        return "{info:ok}";
    }

    @GetMapping("/dept/{did}")
    public Dept GetDept(@PathVariable("did") Integer did) {
        Dept dept = deptService.SelectDeptByEid(did);
        log.info("selectdept:"+dept);
        return dept;
    }

    @GetMapping("/dept")
    public List<Dept> GetDepts() {
        List<Dept> depts = deptService.selectAllDept();
        log.info("selectdept:"+depts);
        return depts;
    }
}
